package com.cjjd.c.feature.subscribe.info;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.RatingBar;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.subscribe.HotelCommentModel;
import com.cjjd.c.bean.subscribe.HotelCommentShowModel;
import com.cjjd.c.feature.home.shoping.evaluate.EvaluateAdapter;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/12/14.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class HotelEvaluateFragment extends BaseSwipeRefreshFragment {

    TextView tvPoint;
    TextView tvPointLevel;
    RatingBar rbGw;
    RatingBar rbQt;
    RatingBar rbGj;
    RatingBar rbBj;

    private HotelCommentModel<HotelCommentShowModel> evaluateList;

    @Override
    public Object getTitleString() {
        return "全部评价";
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {

        evaluateList = (HotelCommentModel<HotelCommentShowModel>) response.body().getData();
        setDataList(evaluateList.dataList);
        //
        tvPoint.setText(evaluateList.score);
        tvPointLevel.setText(evaluateList.scoreLevel);
        rbGw.setNumStars(evaluateList.getScore_yx());
        rbQt.setNumStars(evaluateList.getScore_qt());
        rbGj.setNumStars(evaluateList.getScore_gj());
        rbBj.setNumStars(evaluateList.getScore_bj());

    }

    @Override
    protected void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_header_hotel_evaluate, listBase, false);
        tvPoint = (TextView) view.findViewById(R.id.tv_point);
        tvPointLevel = (TextView) view.findViewById(R.id.tv_point_level);
        rbGw = (RatingBar) view.findViewById(R.id.rb_gw);
        rbQt = (RatingBar) view.findViewById(R.id.rb_qt);
        rbGj = (RatingBar) view.findViewById(R.id.rb_gj);
        rbBj = (RatingBar) view.findViewById(R.id.rb_bj);

        listBase.addHeaderView(view);
        super.initView();
    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new EvaluateAdapter(mContext);
    }

    @Override
    public Call<HttpResult> getCall() {

//        List<String> data = new ArrayList<>();
//        data.add("1");
//        data.add("1");
//        data.add("1");
//        setDataList(data);
//
//        return null;
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("hotelUuid", "0424252f017e49289b68c9987d6b6e0d");
        h1.put("pageNow", PAGE + "");
        h1.put("pageShow", PAGE_SIZE + "");

        return service.getHotelAppInfo(JsonUtils.convertParam("getHotelAppInfo", h1));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
